import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.HashMap;

public class Anagrams {

	
    public List<String> anagrams(String[] strs) {
    	HashMap<String, ArrayList<String>> hm = new HashMap<String, ArrayList<String>>();
    	ArrayList<String> rel = new ArrayList();
    	for(int i =0; i<strs.length; i++){
    		char[] sc = strs[i].toCharArray();
    		Arrays.sort(sc);
    		String s = new String(sc);
    		if(hm.containsKey(s)){
    			hm.get(s).add(strs[i]);
    		}
    		else{
    			ArrayList<String> l= new ArrayList();
    			l.add(strs[i]);
    			hm.put(s, l);
    		}
    	}
    	
    	for(ArrayList<String> sl:hm.values()){
    		if(sl.size()>1)
    			rel.addAll(sl);
    	}
		return rel;
        
    }
	
	private String Wordsort(String str) {
		StringBuffer s=new StringBuffer(str);
		for(int i = 0; i< s.length();i++){
			char a=s.charAt(i);
			int min=i;
			for(int j=i+1;j<s.length();j++){
				if(a>s.charAt(j)){
					a = s.charAt(j);
					min=j;
				}
			}
			if(min!=i){
				s.setCharAt(min, s.charAt(i));
				s.setCharAt(i, a);
			}
		}
		
		// TODO Auto-generated method stub
		return s.toString();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String[] strs = {"bas","sab","daa"};
		System.out.println(new Anagrams().anagrams(strs));

	}

}
